/**
 * 
 */
package com.mobi.Survey.lib.model;

/**
 * @author yahya
 * 
 */
public class Address extends Pojo {

	private long surveyId;
	private String streetNumber;
	private String streetName;
	private String city;
	private String state;
	private String country;
	private String zip;
	private LatLong coordinates;

	public LatLong getCoordinates() {
		return coordinates;
	}

	public void setCoordinates(LatLong coordinates) {
		this.coordinates = coordinates;
	}

	public boolean isAddressNull() {
		return (zip == null && country == null && city == null
				&& streetNumber == null && streetName == null && state == null);
	}

	public String getStreetNumber() {
		return streetNumber;
	}

	public void setStreetNumber(String streetNumber) {
		this.streetNumber = streetNumber;
	}

	public String getStreetName() {
		return streetName;
	}

	public void setStreetName(String streetName) {
		this.streetName = streetName;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getState() {
		return state;
	}

	public void setState(String state) {
		this.state = state;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getZip() {
		return zip;
	}

	public void setZip(String zip) {
		this.zip = zip;
	}

	public long getSurveyId() {
		return surveyId;
	}

	public void setSurveyId(long surveyId) {
		this.surveyId = surveyId;
	}

	@Override
	public boolean equals(Object o) {

		if (o == this) {
			return true;
		}
		if (!(o instanceof Address)) {
			return false;
		}

		if (null == this.streetNumber) {
			this.streetName = "";
		}
		if (null == this.streetName) {
			this.streetName = "";
		}
		if (null == this.city) {
			this.streetName = "";
		}
		if (null == this.state) {
			this.streetName = "";
		}
		if (null == this.country) {
			this.streetName = "";
		}
		if (null == this.zip) {
			this.streetName = "";
		}

		Address address = (Address) o;
		if (null == address.streetNumber) {
			address.streetName = "";
		}
		if (null == address.streetName) {
			address.streetName = "";
		}
		if (null == address.city) {
			address.streetName = "";
		}
		if (null == address.state) {
			address.streetName = "";
		}
		if (null == address.country) {
			address.streetName = "";
		}
		if (null == address.zip) {
			address.streetName = "";
		}

		if (this.city.equalsIgnoreCase(address.city)
				&& this.country.equalsIgnoreCase(address.country)
				&& this.state.equalsIgnoreCase(address.state)
				&& this.zip.equalsIgnoreCase(address.zip)
				&& this.streetName.equalsIgnoreCase(address.streetName)
				&& this.streetNumber.equalsIgnoreCase(address.streetNumber)) {
			return true;
		}

		return false;
	}

	@Override
	public int hashCode() {

		if (null == this.streetNumber) {
			this.streetName = "";
		}
		if (null == this.streetName) {
			this.streetName = "";
		}
		if (null == this.city) {
			this.streetName = "";
		}
		if (null == this.state) {
			this.streetName = "";
		}
		if (null == this.country) {
			this.streetName = "";
		}
		if (null == this.zip) {
			this.streetName = "";
		}

		return (this.streetNumber.hashCode() + this.streetName.hashCode()
				+ this.city.hashCode() + this.state.hashCode()
				+ this.country.hashCode() + this.zip.hashCode());
	}

	@Override
	public String toString() {
		String query = (this.getStreetNumber() == null ? "" : this
				.getStreetNumber() + "+")
				+ (this.getStreetName() == null ? "" : this.getStreetName()
						+ "+")
				+ (this.getCity() == null ? "" : this.getCity() + "+")

				+ (this.getState() == null ? "" : this.getState() + "+")
				+ (this.getCountry() == null ? "" : this.getCountry() + "+")
				+ (this.getZip() == null ? "" : this.getZip());

		return query;
	}
}
